﻿using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Joyintech.Common;
using Joyintech.Model.inpiao365;
using Joyintech.DALFactory;
using Joyintech.IDAL.inpiao365;


namespace Joyintech.BLL.inpiao365
{
    /// <summary>
    /// 业务逻辑类movieOn_BLL 的摘要说明。
    /// </summary>
    public partial class movieOn_BLL
    {
        private readonly ImovieOn_DAL dal = DataAccess.CreatemovieOn_DAL();
        public movieOn_BLL()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int MovieId, int CityId)
        {
            return dal.Exists(MovieId, CityId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Joyintech.Model.inpiao365.movieOn model, DbTransaction trans = null)
        {
            return dal.Add(model, trans);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddAutoCheck(Joyintech.Model.inpiao365.movieOn model, DbTransaction trans = null)
        {
            return dal.AddAutoCheck(model, trans);
        }

        /// <summary>
        /// 批量新增数据
        /// </summary>
        public int AddList(List<Joyintech.Model.inpiao365.movieOn> list)
        {
            return dal.AddList(list);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(Joyintech.Model.inpiao365.movieOn model, DbTransaction trans = null)
        {
            return dal.Update(model, trans);
        }

        /// <summary>
        /// 更新一条数据:自动忽略为null值的字段
        /// </summary>
        public int UpdateAutoCheck(Joyintech.Model.inpiao365.movieOn model, DbTransaction trans = null)
        {
            return dal.UpdateAutoCheck(model, trans);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateList(List<Joyintech.Model.inpiao365.movieOn> list)
        {
            return dal.UpdateList(list);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(int MovieId, int CityId, DbTransaction trans = null)
        {

            return dal.Delete(MovieId, CityId, trans);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Joyintech.Model.inpiao365.movieOn GetModel(int MovieId, int CityId)
        {

            return dal.GetModel(MovieId, CityId);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public Joyintech.Model.inpiao365.movieOn GetModelByCache(int MovieId, int CityId)
        {

            string CacheKey = "movieOnModel-" + MovieId + CityId;
            object objModel = DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(MovieId, CityId);
                    if (objModel != null)
                    {
                        int ModelCache = ConfigHelper.GetConfigInt("ModelCache");
                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Joyintech.Model.inpiao365.movieOn)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Joyintech.Model.inpiao365.movieOn> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Joyintech.Model.inpiao365.movieOn> DataTableToList(DataTable dt)
        {
            List<Joyintech.Model.inpiao365.movieOn> modelList = new List<Joyintech.Model.inpiao365.movieOn>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Joyintech.Model.inpiao365.movieOn model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Joyintech.Model.inpiao365.movieOn();
                    if (dt.Columns.Contains("MovieId"))
                    {
                        if (dt.Rows[n]["MovieId"].ToString() != "")
                        {
                            model.MovieId = Convert.ToInt32(dt.Rows[n]["MovieId"].ToString());
                        }
                    }
                    model.MovieName = dt.Rows[n]["MovieName"].ToString();
                    model.Director = dt.Rows[n]["Director"].ToString();
                    model.ToStar = dt.Rows[n]["ToStar"].ToString();
                    model.MovieType = dt.Rows[n]["MovieType"].ToString();
                    model.Country = dt.Rows[n]["Country"].ToString();
                    if (dt.Columns.Contains("Trailer"))
                    {
                        if (dt.Rows[n]["Trailer"].ToString() != "")
                        {
                            model.Trailer = Convert.ToInt32(dt.Rows[n]["Trailer"].ToString());
                        }
                    }
                    if (dt.Rows[n]["ReleaseDate"].ToString() != "")
                    {
                        model.ReleaseDate = Convert.ToDateTime(dt.Rows[n]["ReleaseDate"].ToString());
                    }
                    model.MovieContent = dt.Rows[n]["MovieContent"].ToString();
                    model.MovieBehind = dt.Rows[n]["MovieBehind"].ToString();
                    model.MovieLogo = dt.Rows[n]["MovieLogo"].ToString();
                    model.MovieStills = dt.Rows[n]["MovieStills"].ToString();
                    if (dt.Columns.Contains("MoviePrice"))
                    {
                        if (dt.Rows[n]["MoviePrice"].ToString() != "")
                        {
                            model.MoviePrice = decimal.Parse(dt.Rows[n]["MoviePrice"].ToString());
                        }
                    }
                    if (dt.Columns.Contains("CityId"))
                    {
                        if (dt.Rows[n]["CityId"].ToString() != "")
                        {
                            model.CityId = Convert.ToInt32(dt.Rows[n]["CityId"].ToString());
                        }
                    }
                    if (dt.Columns.Contains("TheaterId"))
                    {
                        if (dt.Rows[n]["TheaterId"].ToString() != "")
                        {
                            model.TheaterId = Convert.ToInt32(dt.Rows[n]["TheaterId"].ToString());
                        }
                    }
                    model.TheaterName = dt.Rows[n]["TheaterName"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        #endregion  成员方法
    }
}

